/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.activity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ykht.proj.activity.Enum.PayTypeEnum;
import com.ykht.proj.activity.vo.EntOrderDto;
import com.ykht.proj.activity.vo.EntOrderReq;
import com.ykht.proj.activity.vo.GetVOrderVO;
import com.ykht.proj.activity.vo.VOrderPageReq;
import com.ykht.proj.activity.vo.VOrderPageResp;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.log.annotation.SysLog;
import com.ykht.proj.activity.entity.VOrder;
import com.ykht.proj.activity.service.VOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;



/**
 * 订单(企业 用户购买卡订单)表
 *
 * @author csg
 * @date 2021-05-21 14:22:31
 */
@RestController
@AllArgsConstructor
@RequestMapping("/vorder" )
@Api(value = "vorder", tags = "订单(企业 用户购买卡订单)表管理")
@Slf4j
public class VOrderController {

    private final  VOrderService vOrderService;

    @ApiOperation(value = "分页查询订单", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('activity_vorder_view')" )
    public R<Page<VOrderPageResp>> getVOrderPage(Page<VOrder> page, VOrderPageReq req) {
        return vOrderService.getVOrderPage(page, req);
    }

	@ApiOperation(value = "订单详情")
	@GetMapping("/getVOrder" )
	public R<GetVOrderVO> getVOrder(Long orderId) {
		return vOrderService.getVOrderVO(orderId);
	}


    /**
     * 通过id查询订单(企业 用户购买卡订单)表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('activity_vorder_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(vOrderService.getById(id));
    }

    /**
     * 新增订单(企业 用户购买卡订单)表
     * @param vOrder 订单(企业 用户购买卡订单)表
     * @return R
     */
    @ApiOperation(value = "新增订单(企业 用户购买卡订单)表", notes = "新增订单(企业 用户购买卡订单)表")
    @SysLog("新增订单(企业 用户购买卡订单)表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('activity_vorder_add')" )
    public R save(@RequestBody VOrder vOrder) {
        return R.ok(vOrderService.save(vOrder));
    }

    /**
     * 修改订单(企业 用户购买卡订单)表
     * @param vOrder 订单(企业 用户购买卡订单)表
     * @return R
     */
    @ApiOperation(value = "修改订单(企业 用户购买卡订单)表", notes = "修改订单(企业 用户购买卡订单)表")
    @SysLog("修改订单(企业 用户购买卡订单)表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('activity_vorder_edit')" )
    public R updateById(@RequestBody VOrder vOrder) {
        return R.ok(vOrderService.updateById(vOrder));
    }

    /**
     * 通过id删除订单(企业 用户购买卡订单)表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除订单(企业 用户购买卡订单)表", notes = "通过id删除订单(企业 用户购买卡订单)表")
    @SysLog("通过id删除订单(企业 用户购买卡订单)表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('activity_vorder_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(vOrderService.removeById(id));
    }


	@ApiOperation(value = "获取 支付方式")
	@PostMapping("/getPayTypeEnum")
	public R getPayTypeEnum() {
		log.info("->获取 支付方式");
		return R.ok(PayTypeEnum.map);
	}

	/**
	 * 企业购买卡（代客下单）
	 * @param entOrderReq 企业购买卡
	 * @return R
	 */
	@ApiOperation(value = "企业购买卡（代客下单）", notes = "企业购买卡（代客下单）")
	@SysLog("企业购买卡（代客下单）" )
	@PostMapping("/addEntBuyCard")
	public R addEntBuyCard(@RequestBody EntOrderReq entOrderReq) {
		log.info("->企业购买卡（代客下单）{}", entOrderReq);
		if (null == entOrderReq.getEntOrderCardReqList() || entOrderReq.getEntOrderCardReqList().size() == 0) {
			return R.failed("请选择卡");
		}
		return vOrderService.addEntBuyCard(entOrderReq);
	}


	/**
	 * 企业购买卡记录 分页查询
	 * @param page 分页对象
	 * @param entOrderDto 订单(企业 用户购买卡订单)表
	 * @return
	 */
	@ApiOperation(value = "企业购买卡记录 分页查询", notes = "企业购买卡记录 分页查询")
	@GetMapping("/getEntBuyCardListPage" )
	public R getEntBuyCardListPage(Page page, EntOrderDto entOrderDto) {
		log.info("->企业购买卡记录 分页查询{}{}", page, entOrderDto);
		IPage<EntOrderDto> iPage = vOrderService.getEntBuyCardListPage(page, entOrderDto);
		return R.ok(iPage);
	}


}
